package com.stargate.bd.dao.factory;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;

import com.stargate.bd.bean.JourFerie;
import com.stargate.bd.dao.DAO;

public class JourFerieDAO extends DAO<JourFerie>{

	@Override
	public ArrayList<JourFerie> selectAll() throws SQLException {
		ArrayList<JourFerie> joursFeries = new ArrayList<JourFerie>();
		String sql = "select * from JOUR_FERIE";
		Statement statement = connection.createStatement();
		ResultSet result = statement.executeQuery(sql);
		while (result.next()) {
			joursFeries.add(new JourFerie(result.getDate(JourFerie.DATE_FERIE)));
		}
		result.close();
		statement.close();
		return joursFeries;
	}

	@Override
	public JourFerie select(JourFerie bean) throws SQLException {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("Not yet implemented");
	}

	@Override
	public void update(JourFerie bean) throws SQLException {
		String sql = "UPDATE " + JourFerie.TABLE_NAME +
				" SET " + JourFerie.DATE_FERIE + "=?" +
				" WHERE " + JourFerie.DATE_FERIE + "=?";
		PreparedStatement statement = connection.prepareStatement(sql);
		statement.setObject(1, bean.getDateFerie(), Types.DATE);
		statement.setObject(2, bean.getDateFerie(), Types.DATE);
		statement.executeUpdate();
		statement.close();
	}

	@Override
	public void delete(JourFerie bean) throws SQLException {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("Not yet implemented");
	}

	@Override
	public void insert(JourFerie bean) throws SQLException {
		System.out.println("*** Insertion de " + bean + "***");
		String sql = "INSERT INTO " + JourFerie.TABLE_NAME + " VALUES (?)";
		PreparedStatement statement = connection.prepareStatement(sql);
		statement.setObject(1, bean.getDateFerie(), Types.DATE);
		statement.executeUpdate();
		statement.close();
	}

	
}
